package cn.rcth.controller;

import cn.rcth.base.domain.Product;
import cn.rcth.base.msg.ResultMsg;
import cn.rcth.base.serivce.IProductSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 商品
 */
@Controller
public class ProductController {

    @Autowired
    private IProductSerivce productSerivce;

    /**
     * 商品首页
     * @return  商品信息
     */
    @RequestMapping(value = "/product", method = RequestMethod.GET)
    @ResponseBody
    public ResultMsg product(){
        List<Product> products = productSerivce.getProductAll();
        return ResultMsg.successResult(products);
    }

    /**
     * 商品详情
     * @param productId  商品Id   three
     * @return  商品详情
     */
    @RequestMapping(value = "/productDetails" ,method = RequestMethod.GET)
    @ResponseBody
    public ResultMsg productDetails(Long productId) {
        Map<String,Object> product = productSerivce.getProduct(productId);
        return ResultMsg.successResult(product);
    }

}
